<!--
 * @Author: zjf
 * @Date: 2023-01-31 10:51:21
 * @LastEditors: zjf
 * @LastEditTime: 2023-12-04 14:04:01
 * @Description:
-->
<template>
  <div class="l-rblock l-form-viewer" style="padding:16px 16px 0 16px">
    <el-form :model="formData" :rules="rules" size="mini" ref="form">
      <div class="l-rblock">
        <el-form-item prop="f_Name">
          <el-input v-model="formData.f_Name" :placeholder="$t('请输入名称')">
          </el-input>
        </el-form-item>
      </div>
    </el-form>
  </div>
</template>
<script>
export default {
  data() {
    return {
      moduleCode: "learun-file",
      formData: {
        f_Name: "", // 名称
      },
      rules: {
        f_Name: [
          { required: true, message: "请输入名称" },
          {
            validator: this.lr_existDbFiled,
            keyValue: () => { return this.formData.f_Id },
            tableName: 'lr_base_folder',
            keyName: 'f_Id',
            filedsJsonName: 'fileFolderForm_filedsJson',
            message: "文件夹名重复",
            trigger: 'null'
          }
        ],
      },
      pid: ''
    };
  },
  computed: {
    fileFolderForm_filedsJson() {
      return { f_PId: this.pid, f_DeleteMark: 0 }
    }

  },
  methods: {
    // 重置表单
    resetForm() {
      this.formData.f_Id = ''
      this.formData.f_PId = ''
      this.pid = ''
      this.$formClear(this.$refs.form)
    },
    // 校验表单
    async validateForm(pid) {
      this.pid = pid

      if (!(await this.$formValidateWraper(this.$refs.form))) {
        return false
      }
      return true
    },
    // 设置表单数据
    setForm(data) {
      this.formData = data
    },
    // 获取表单数据
    getForm() {
      return this.$deepClone(this.formData)
    },

    async saveForm({ keyValue, pid, projectId, businessId, levelId, isEdit, businessCode }) {
      const api = window.$crud('dir');
      const postData = this.getForm()
      let data = {
        "ArchivesProjectDir": {
          "ProjectId": projectId,
          "ParentId": pid,
          "BusinessId": businessId,
          "DirName": postData.f_Name,
          "ConfigBusinessId": businessCode
        },
        "FolderEntity": {
          "f_Name": postData.f_Name,
          "f_PId": pid,
          "f_LevelId": levelId
        }
      }
      if (isEdit) {
        // 编辑
        return await this.$awaitWraper(api.update(keyValue, data))
      } else {
        // 新增
        return await this.$awaitWraper(api.add(data))
      }
    },
  },
};
</script>